#include<iostream>

using namespace std;

int n,a[10],b[10];

void dfs(int num){
    int i;
    if (n==num)
    {
        for(i=0;i<n;)printf("%5d",a[i++]);
        putchar('\n');
        return;
    }
    for (i= 1; i <= n; i++)
    {
        if(b[i])continue;
        b[i]=1;
        a[num]=i;
        dfs(num+1);
        b[i]=0;
    }
}

int main(int argc, char const *argv[])
{
    scanf("%d",&n);
    dfs(0);
}

